package cc.mrbird.febs.system.service.impl;

import cc.mrbird.febs.common.entity.QueryRequest;

import cc.mrbird.febs.system.entity.DetailInfo;
import cc.mrbird.febs.system.mapper.DetailInfoMapper;
import cc.mrbird.febs.system.service.IDetailInfoService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.annotation.Propagation;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import javax.annotation.Resource;
import java.util.List;

/**
 *  Service实现
 *
 * @author MrBird
 * @date 2019-07-22 11:18:47
 */
@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class DetailInfoServiceImpl extends ServiceImpl<DetailInfoMapper, DetailInfo> implements IDetailInfoService {

    @Resource
    private DetailInfoMapper detailInfoMapper;

    @Override
    public IPage<DetailInfo> findDetailInfos(QueryRequest request, DetailInfo detailInfo) {
        LambdaQueryWrapper<DetailInfo> queryWrapper = new LambdaQueryWrapper<>();
        // TODO 设置查询条件
        if(null!=detailInfo){
            String drawingId=detailInfo.getDrawingDetailId();
            if(StringUtils.isNotBlank(drawingId)){
                queryWrapper.eq(DetailInfo::getDrawingDetailId,drawingId);
            }

        }
        Page<DetailInfo> page = new Page<>(request.getPageNum(), request.getPageSize());
        return this.page(page, queryWrapper);
    }

    @Override
    public List<DetailInfo> findDetailInfos(DetailInfo detailInfo) {
	    LambdaQueryWrapper<DetailInfo> queryWrapper = new LambdaQueryWrapper<>();
		// TODO 设置查询条件
		return this.baseMapper.selectList(queryWrapper);
    }

    @Override
    @Transactional
    public void createDetailInfo(DetailInfo detailInfo) {
        this.save(detailInfo);
    }

    @Override
    @Transactional
    public void updateDetailInfo(DetailInfo detailInfo) {
        this.saveOrUpdate(detailInfo);
    }

    @Override
    @Transactional
    public void deleteDetailInfo(DetailInfo detailInfo) {
        LambdaQueryWrapper<DetailInfo> wapper = new LambdaQueryWrapper<>();
	    // TODO 设置删除条件
	    this.remove(wapper);
	}

    @Override
    public int batchDelete(String[] ids) {
        return this.baseMapper.batchDelete(ids);
    }
}
